package com.ziq.zcamp.mine

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.ziq.base.base.BaseActivity
import com.ziq.base.extension.binding
import com.ziq.base.extension.click
import com.ziq.zcamp.R
import com.ziq.zcamp.databinding.ActivitySettingBinding
import com.ziq.zcamp.dialog.AlertDialog
import com.ziq.zcamp.main.MainActivity
import com.ziq.zcamp.main.MainFragment
import com.ziq.zcamp.manager.GlobalContextManager
import com.ziq.zcamp.manager.UserManager
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class SettingPageActivity : BaseActivity() {

    companion object {
        fun open(context: Context){
            val intent = Intent(context, SettingPageActivity::class.java)
            GlobalContextManager.startActivity(context, intent)
        }
    }


    private val binding : ActivitySettingBinding by binding()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.root
        binding.back.click {
            finish()
        }
        binding.logout.click {
            onShowLogout()
        }
    }


    private fun onShowLogout(){
        AlertDialog(this)
            .setTitle {
                it.append(GlobalContextManager.getString(R.string.are_you_sure_logout))
            }
            .setCancelButton(text = {it.append(GlobalContextManager.getString(R.string.cancel))}, action = {
                it.dismiss()
            })
            .setConfirmButton(text = {it.append(GlobalContextManager.getString(R.string.confirm))}, action = {
                it.dismiss()
                logout()
            })
            .show()
    }

    fun logout(){
        UserManager.instance.logout()
        MainActivity.backToHomeTab(this, MainFragment.MainTab.MAIN_TAB_PLACE.value)
    }
}